package com.fap.core.bo.define;

import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fap.core.bo.BusinessObject;
import com.fap.core.bo.meta.BoMeta;

@Component(value="boDefineRepository")
public class BoDefineRepository {

	@Autowired
	private BoDefineActionMapper _boDefine;
	@Autowired
	private FieldDefineActionMapper _fieldDefine;
	
	private List<BoMeta> _boMetas = new ArrayList<BoMeta>();
	
	public void registerAllBoDefine(){
		List<BoDefine> boDefines = _boDefine.getAllDefines();
		System.out.println("defines count:"+boDefines.size());
		for(BoDefine bd: boDefines){
//			System.out.println(bd.getId());
//			System.out.println(bd.getTableName());
//			System.out.println(bd.getTag());
//			System.out.println(bd.getName());
//			System.out.println(bd.getPrimaryField());
//			System.out.println(bd.getIsUsed());
//			System.out.println(bd.getIsPrivilegeDimension());
			bd.setFieldDefines(_fieldDefine.getAllDefines(bd.getId()));
			_boMetas.add(new BoMeta(bd));
		}
	}
	
	public BoMeta getMetaByTag(String tag){
		for(BoMeta meta: _boMetas){
			if(meta.getTag().equals(tag))
				return meta;
		}
		return null;
	}
}
